Function Reference

_GUICtrlComboSetCurSel

Select a string in the list of a combo box

#Include <GuiCombo.au3>
_GUICtrlComboSetCurSel($h_combobox,$i_index)

 

Parameters

$h_combobox control id/control hWnd
$i_index Specifies the zero-based index of the string to select

 

Return Value

Success: Returns the index of the item selected.
Failure: Returns $CB_ERR if $i_index is greater than the number of items in the list or if $i_index is û1 and the selection is cleared.
Returns $CB_ERRSPACE if there is insufficient space to store the new strings.

 

Remarks

If this $i_index is û1, any current selection in the list is removed and the edit control is cleared

 

Related

_GUICtrlComboGetCurSel

 

Example


#include <GuiConstants.au3>
#include <GuiCombo.au3>

Opt('MustDeclareVars',1)

Dim $Label,$Input,$Btn_Set,$Combo,$Btn_Exit,$msg,$ret

GuiCreate("ComboBox Set Cur Sel", 392, 254)

$Label = GuiCtrlCreateLabel("Enter Index to Set", 20, 20, 120, 20)
$Input = GuiCtrlCreateInput("", 160, 20, 180, 20,$ES_NUMBER)
GUICtrlSetLimit($Input,1)
$Btn_Set = GuiCtrlCreateButton("Set Cur Sel", 160, 50, 90, 30)
$Combo = GuiCtrlCreateCombo("", 70, 100, 270, 100,$CBS_SIMPLE)
GUICtrlSetData($Combo,"AutoIt|v3|is|freeware|BASIC-like|scripting|language")
$Btn_Exit = GuiCtrlCreateButton("Exit", 150, 200, 90, 30)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
        Case $msg = $Btn_Set
            If(StringLen(GUICtrlRead($Input)) > 0) Then
                $ret = _GUICtrlComboSetCurSel($Combo,Int(GUICtrlRead($Input)))
            EndIf
    EndSelect
WEnd
Exit